package com.kepler.social.web.configuration;

import org.apache.commons.lang3.StringUtils;
import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.redisson.config.SingleServerConfig;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Classname RedissonConfig
 * @Description RedissonConfig
 * @Date 9/7/2022 1:54 PM
 */
@Configuration
public class RedissonConfig {


    @Value("${spring.social.redisson.host}")
    private String host;

    @Value("${spring.social.redisson.port}")
    private String port;

    @Value("${spring.social.redisson.password}")
    private String password;

    @Bean("redissonClient")
    public RedissonClient getRedisson() {
        Config config = new Config();
        SingleServerConfig singleServerConfig = config.useSingleServer();
        singleServerConfig
                .setAddress("redis://" + host + ":" + port);
        if (StringUtils.isNotBlank(password)) {
            singleServerConfig
                    .setPassword(password);
        }
        return Redisson.create(config);
    }


}
